
//var tecRefundnoDeal ;       //待处理       
//var tecRefundwaiteseller ;  //待卖家       
//var tecRefundwaitbuyer ;    //待卖家   
var tecRefundSellerAgree; //等待卖家同意
var tecRefundBuyerSend;   //等待买家退货
var tecRefundSellerRecive; //等待卖家确认收货
var tecRefundSellerReject; //卖家拒绝退款
var tecRefundOver ;         //已完成       
var tecRefundcanceled ;     //已废弃   
var searchCondition = {     //高级检索          
//        prjId:"",   
        shopId:"",  
        shopType:"",    
        ecTradeCode:"",
        ecCustCode:"",
        ecItemCode:"",
        ecSkuCode:"",
        dateStart:"",
        dateEnd:"",
        refundReason:"",
        refundStatus:"",
        refundPhase:""  
};          
var quickSearch = "";       //快速查询  
var btnAdvSearchflg= false; //高级查询是否点击标识    
var mapOrderTable = {};

/**
 * 页面初期化
 */
$(document).ready(function () {
    //时间控件
    $('.datetimepicker-default').datetimepicker();
    
    //高级检索初期化的时候隐藏
    $("#advSearchPanel").hide();
    
    //项目的下拉列表
//    $.ajax({
//        type:"GET",
//        url:"/projectManager/getAllAvailableProjects.action",
//        contentType: "application/json;charset=utf-8",
//        dataType: "json",
//        async: true,//同步
//        success:function(data) {
//            if (data.result == "success") {
//                $("#prjId option").remove();
//                $("#prjId").append("<option value=''>请选择</option>");
//                $.each(data.data, function (n, value) {
//                    $("#prjId").append("<option value='" + value.prjId + "'>" + value.prjName + "</option>");
//                });
//            } else {
//                window.top.window.showModalAlert(data.msg);
//            }
//        },
//        error:function(XMLHttpRequest, textStatus) {
//            if (XMLHttpRequest.status == 500) {
//                var result = eval("(" + XMLHttpRequest.responseText + ")");
//                alert(result.errorObject.errorText);
//            }
//        }
//    });
    getShopList();//获取店铺列表接口
    
    /**         
     * 获取店铺列表       
     */         
    function getShopList() {           
        //项目ID          
        var prjId = encodeURI(encodeURI(window.top.window.$("#projectSwitch").val()));            
            
        // 初始化店铺列表          
        $.ajax({            
            type: "GET",            
            url: "/shop/getShopListByPrjId.action?prjId=" + prjId,          
            contentType: "application/json;charset=utf-8",          
            dataType: "json",           
            async: false,//同步           
            success: function (data) {          
                if (data.result == "success") {         
                    $("#shopId option").remove();       
                    $("#shopId").append("<option value=''>请选择</option>");       
                    $.each(data.data, function (n, value) {         
                        $('#shopId').append("<option value='" + value.shopId + "' shopType = '"+value.shopType+"'>" + value.shopName + "</option>");        
                    });         
                } else {            
                    window.top.window.showModalAlert(data.msg);         
                }           
            },          
            error: function (XMLHttpRequest, textStatus) {          
                if (XMLHttpRequest.status == 500) {         
                    var result = eval("(" + XMLHttpRequest.responseText + ")");         
                    alert(result.errorObject.errorText);            
                }           
            }           
        });         
    };         

    //默认待处理显示       
//    getEcRefundnoDeal();  
    getSellerAgree();
    
    //未付款数字,待处理数字,待发货,全部发货,已完成数字,已废弃数字
    getCounts();

    //绑定事件      
    /**     
     * tab切换事件      
     */     
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {      
            
        switch ($(this).attr("id")) {   
        case "portlettabcanceledid":    //已废弃
            getCanceled();
            break;
        case "portlettaboverid":        //已完成
            getOver();  
            break; 
        case "portlettabselleragreeid":       //等待卖家同意
            getSellerAgree();
            break;
        case "portlettabbuyersendid":           //等待买家退货
            getBuyerSend();
            break;
        case "portlettabsellerreciveid":        //等待卖家确认收货
            getSellerRecive();
            break;
        case "portlettabsellerrejectid":        //卖家拒绝退款
            getSellerReject();
            break;
//        case "portlettabwaitebuyerid":      //待买家操作
//            getWaitebuyer();    
//            break;      
//        case "portlettabwaitesellerid": //等待卖家处理
//            getWaiteseller();   
//            break;      
//        case "portlettabnoDealid":  //待处理   
//            getEcRefundnoDeal();    
//            break;      
        default:    
            break;  
        }   
        getCounts();    
            
    });     

    // 高级搜索     
    $("#btnAdvSearch").click(function () {          
        btnAdvSearchflg = true;     
        if ($("#advSearchPanel").is(":hidden")) {           
            $("#btnQuickSearch").hide();
            $("#advSearchPanel").show();            
            $(this).children("i:eq(0)").removeClass("fa-angle-double-down");            
            $(this).children("i:eq(0)").addClass("fa-angle-double-up");         
        } else {            
            $("#advSearchPanel").hide();
            $("#btnQuickSearch").show();            
            $(this).children("i:eq(0)").removeClass("fa-angle-double-up");          
            $(this).children("i:eq(0)").addClass("fa-angle-double-down");           
        }           
                    
    });         
    $("#advSearchPanel").click(function () {
        btnAdvSearchflg = true;
    })
    
    /**         
     * body点击的时候高级检索收回          
     */         
//    $("body").click(function(e){            
//        if(btnAdvSearchflg==true){      
//            btnAdvSearchflg = false;    
//        } else {        
//            $("#advSearchPanel").hide();    
//            $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");           
//            $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");            
//        }       
//    });         

    // 高级搜索“提交”按钮点击         
    $("#advSearchSubmit").click(function (e) {          
        //记录高级查询的检索条件       
        setHidValue("frmAdvSearch");            
        searchCondition = { //高级检索          
//                prjId:$('#hidprjId').val(), 
                shopId:$('#hidshopId').val(),   
                shopType:$('#hidshopType').val(),   
                ecTradeCode:$('#hidecTradeCode').val(), 
                ecCustCode:$('#hidecCustCode').val(),   
                ecItemCode:$('#hidecItemCode').val(),
                ecSkuCode:$('#hidecSkuCode').val(),
                dateStart:$('#hiddateStart').val(),
                dateEnd:$('#hiddateEnd').val(),
                refundReason:$('#hidrefundReason').val(),
                refundStatus:$('#hidrefundStatus').val(),
                refundPhase:$('#hidrefundPhase').val(),
        };          
        quickSearch = ($('#quickSearch').val());
        $("div .active").each(function(){           
            switch ($(this).attr("id")) {   
            case "portlettabcanceled":  //已废弃
                tecRefundcanceled.draw();
                break;
            case "portlettabover":      //已完成
                tecRefundOver.draw();   
                break;
            case "portlettabselleragree":           //等待卖家同意
                tecRefundSellerAgree.draw();
                break;
            case "portlettabbuyersend":             //等待买家退货
                tecRefundBuyerSend.draw();
                break;
            case "portlettabsellerrecive":          //等待卖家确认收货
                tecRefundSellerRecive.draw();
                break;
            case "portlettabsellerreject":          //卖家拒绝退款
                tecRefundSellerReject.draw();
                break;
//            case "portlettabwaitebuyer":        //待买家
//                tecRefundwaitbuyer.draw();  
//                break;      
//            case "portlettabwaiteseller":       //待卖家
//                tecRefundwaiteseller.draw();    
//                break;      
//            case "portlettabnoDeal":        //待处理
//                tecRefundnoDeal.draw(); 
//                break;      
            default:    
                break;  
            }   
        });     
        getCounts();            
//        $("#advSearchPanel").hide();            
//        $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");           
//        $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");            
                    
    });         

    /**         
     * 快速搜索，点击时提交表格刷新内容         
     */         
    $("#btnQuickSearch").click(function () {            
        quickSearch = ($('#quickSearch').val());       
        searchCondition = { //高级检索      
//                prjId:"",   
                shopId:"",  
                shopType:"",    
                ecTradeCode:"",
                ecCustCode:"",
                ecItemCode:"",
                ecSkuCode:"",
                dateStart:"",
                dateEnd:"",
                refundReason:"",
                refundStatus:"",
                refundPhase:"",
        };      
        $("div .active").each(function(){       
            switch ($(this).attr("id")) {   
            case "portlettabcanceled":  //已废弃
                tecRefundcanceled.draw();
                break;
            case "portlettabover":      //已完成
                tecRefundOver.draw();   
                break;    
            case "portlettabselleragree":           //等待卖家同意
                tecRefundSellerAgree.draw();
                break;
            case "portlettabbuyersend":             //等待买家退货
                tecRefundBuyerSend.draw();
                break;
            case "portlettabsellerrecive":          //等待卖家确认收货
                tecRefundSellerRecive.draw();
                break;
            case "portlettabsellerreject":          //卖家拒绝退款
                tecRefundSellerReject.draw();
                break;
//            case "portlettabwaitebuyer":        //待买家
//                tecRefundwaitbuyer.draw();  
//                break;      
//            case "portlettabwaiteseller":       //待卖家
//                tecRefundwaiteseller.draw();    
//                break;      
//            case "portlettabnoDeal":        //待处理
//                tecRefundnoDeal.draw(); 
//                break;      
            default:    
                break;  
            }   
        });     
        getCounts();        
    }); 
    
    /**         
     * 搜索框的回车事件         
     */             
    $('#quickSearch').keydown(function(e){          
        if(e.keyCode==13 && $('#btnQuickSearch').is(":visible")){          
            $("#btnQuickSearch").click();           
        }           
    });         

    //子表格显示隐藏           
    $('.tablefirst tbody').on('click', 'td .fa', function () {          
        //取得主键          
        var ecRefundId = $(this).attr('ecRefundId');            
        //取得行           
        var tr = $(this).closest('tr');         
        var row;            
        var table;          
        var tablename =  "";            
        var tabIndex = "";          
        $("div .active").each(function(){           
            switch ($(this).attr("id")) {   
            case "portlettabcanceled":  //已废弃
                table = tecRefundcanceled;
                row = tecRefundcanceled.row(tr);
                tablename = "tecRefundcanceled";
                tabIndex = "canceled";
                break;
            case "portlettabover":      //已完成
                table = tecRefundOver;  
                row = tecRefundOver.row(tr);    
                tablename = "tecRefundOver";    
                tabIndex = "over";  
                break;
            case "portlettabselleragree":           //等待卖家同意
                table = tecRefundSellerAgree;  
                row = tecRefundSellerAgree.row(tr);    
                tablename = "tecRefundSellerAgree";    
                tabIndex = "agree";
                break;
            case "portlettabbuyersend":             //等待买家退货
                table = tecRefundBuyerSend;  
                row = tecRefundBuyerSend.row(tr);    
                tablename = "tecRefundBuyerSend";    
                tabIndex = "send";
                break;
            case "portlettabsellerrecive":          //等待卖家确认收货
                table = tecRefundSellerRecive;  
                row = tecRefundSellerRecive.row(tr);    
                tablename = "tecRefundSellerRecive";    
                tabIndex = "recive";
                break;
            case "portlettabsellerreject":          //卖家拒绝退款
                table = tecRefundSellerReject;  
                row = tecRefundSellerReject.row(tr);    
                tablename = "tecRefundSellerReject";    
                tabIndex = "reject";
                break;
//            case "portlettabwaitebuyer":        //待买家
//                table = tecRefundwaitbuyer; 
//                row = tecRefundwaitbuyer.row(tr);   
//                tablename = "tecRefundwaitbuyer";   
//                tabIndex = "waitbuyer"; 
//                break;      
//            case "portlettabwaiteseller":       //待卖家
//                table = tecRefundwaiteseller;   
//                row = tecRefundwaiteseller.row(tr); 
//                tablename = "tecRefundwaiteseller"; 
//                tabIndex = "waiteseller";   
//                break;      
//            case "portlettabnoDeal":        //待处理
//                table = tecRefundnoDeal;    
//                row = tecRefundnoDeal.row(tr);  
//                tablename = "tecRefundnoDeal";  
//                tabIndex = "noDeal";    
//                break;  
            default:    
                break;  
            }   
        });     
        //加载过，而且是显示的状态          
        if ( row.child.isShown() ) {            
            // This row is already open - close it          
            row.child.hide();       
            tr.removeClass('shown');            
            $(this).removeClass('fa-chevron-up');           
            $(this).addClass('fa-chevron-down');            
        }           
        else {          
            //关闭其他          
            $('#'+tablename+' tbody tr').each(function(){       
                if ($(this).attr("role")=="row"){   
                    table.row($(this)).child.hide();
                }   
            });     
            $('.fa-chevron-up').addClass('fa-chevron-down');            
            $('.fa-chevron-down').removeClass('fa-chevron-up');         
            //生成datatable的HTML代码            
            //判断相应的id的datatable是否存在         
            if ($('#' + tablename + ecRefundId + tabIndex).length <= 0) {           
                var temp = '';          
                temp += '<table id="' + tablename + ecRefundId + tabIndex +'"'; 
                temp += 'class="table table-hover table-striped table-bordered table-advanced tb-sticky-header"';
                temp += 'width="100%">';
                temp += '<thead>';          
                temp += '<tr>';         
//                temp += '<th width="5%">异常描述</th>';         
                temp += '<th width="5%">平台商品编码</th>';           
                temp += '<th width="5%">平台商品名称</th>';           
//                temp += '<th width="5%">平台规格编码</th>';           
                temp += '<th width="5%">平台规格编码/名称</th>';           
                temp += '<th width="5%">平台状态</th>';         
//                temp += '<th width="5%">分单店铺</th>';         
//                temp += '<th width="5%">系统状态</th>';         
                temp += '<th width="5%">买家是否退货</th>';   
                temp += '<th width="5%">退款金额</th>';
                temp += '<th width="5%">退款原因</th>';         
                temp += '<th width="5%">退款阶段</th>';         
                temp += '<th width="5%">退回物流单号</th>';
                temp += '</tr>';            
                temp += '</thead>';         
                temp += '<tbody>';          
                temp += '</tbody>';         
                temp += '</table>';         
                // Open this row            
                row.child(temp).show();         
                tr.addClass('shown');           
                
                mapOrderTable[tablename + ecRefundId + tabIndex] = $('#' + tablename + ecRefundId + tabIndex).DataTable({       
                    "bPaginate": false,         
                    "processing": true,         
                    "serverSide": true,         
                    "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],          
                    "dom": '<"bottom"rtfli>',           
                    "searching": false,         
                    "pagingType": "full_numbers",           
                    "deferRender": true,            
                    "ajax": {           
                        "url": "/ecRefundManager/ecRefundOrderList.action",         
                        "data": function (d) {          
                            d.ecRefundId = encodeURI(ecRefundId);           
                        }           
                    },          
                    "tableTools": {         
                        "sRowSelect": "bootstrap"           
                    },          
                    "columns": [            
//                        {"data": "errDesc"},        
                        {"data": "ecItemCode"},     
                        {"data": "ecItemName"},         
//                        {"data": "ecSkuCode"},      
                        {"data": "ecSkuName"},      
                        {"data": "refundStatus"},       
//                        {"data": "splitShopName"},      
//                        {"data": "erpStatus"},      
                        {"data": "hasGoodReturn"},      
                        {"data": "refundFee"},      
                        {"data": "refundReason"},       
                        {"data": "refundPhase"},        
                        {"data": "lgstNo"}      
                    ],          
                    "order": [[2, "asc"]]           
                });
            } else {            
                tr.addClass('shown');       
            }           
            $(this).addClass('fa-chevron-up');          
            $(this).removeClass('fa-chevron-down');         
        }           
    });         

 // 文字过长截断显示悬浮框
    $("#tecRefundSellerAgree").tooltip({
        selector : ".tooltip-column-detail",
        container : "body",
        title : function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
    $("#tecRefundBuyerSend").tooltip({
        selector : ".tooltip-column-detail",
        container : "body",
        title : function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
    $("#tecRefundSellerRecive").tooltip({
        selector : ".tooltip-column-detail",
        container : "body",
        title : function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
    $("#tecRefundSellerReject").tooltip({
        selector : ".tooltip-column-detail",
        container : "body",
        title : function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
    $("#tecRefundOver").tooltip({
        selector : ".tooltip-column-detail",
        container : "body",
        title : function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
    $("#tecRefundcanceled").tooltip({
        selector : ".tooltip-column-detail",
        container : "body",
        title : function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
});

/**         
 * 已废弃 列表           
 * @returns         
 */         
function getCanceled(){         
    //如果已经初期化过，不用重新定义，直接重画表格        
    if (tecRefundcanceled!=null && tecRefundcanceled != undefined && ""!=tecRefundcanceled){        
        tecRefundcanceled.draw();   
        return ;    
    }       
    tecRefundcanceled = $('#tecRefundcanceled').DataTable({     
            "processing": true,     
            "serverSide": true,     
            "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],      
            "dom": '<"bottom"rtflp>',       
            "searching": false,     
            "pagingType": "full_numbers",       
            "deferRender": true,   
            "scrollX" : "100%",
            "scrollY" : "410px",
            "scrollCollapse" : false,
            "ajax": {       
                "url": "/ecRefundManager/ecRefundCanceledList.action",      
                "data": function (d) {      
                        d.quickSearch = quickSearch;        
                        d.formJson = JSON.stringify(searchCondition);       
                    }       
                },      
            "tableTools": {     
                "sRowSelect": "bootstrap"       
            },      
            "columns": [        
                 {"data": "ecRefundItemShow"}   
//                ,{"data": "exceptionType"}  
//                ,{"data": "prjName"}    
                ,{"data": "shopName"}   
                ,{"data": "shopType"}
                ,{"data": "buyerNick"}
                ,{"data": "ecTradeCode"}
                ,{"data": "ecRefundCode"}
                ,{"data": "refundStatusNm"}  
                ,{"data": "refundTradeStatus"} 
                ,{"data": "refundCreateTime"}
                ,{"data": "refundTimeout"}
                ,{"data": "closeTime"}
                ],  
            "columnDefs": [{        
                "orderable": false,     
                "targets": [0]      
            },{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [1] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [2] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [3] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [4] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [5] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [6] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [7] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [8] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [9] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [10] 
            }    
            ],      
            "order": [[9, "asc"]]      
        }).on('draw.dt',  function() {
        	//解决因滚动条导致的列对不齐问题
            $(".dataTables_scrollBody").css("overflow-y","overlay");
        });
}   

/**         
 * 已完成 列表           
 * @returns         
 */         
function getOver(){         
    //如果已经初期化过，不用重新定义，直接重画表格        
    if (tecRefundOver!=null && tecRefundOver != undefined && ""!=tecRefundOver){        
        tecRefundOver.draw();   
        return ;    
    }       
    tecRefundOver = $('#tecRefundOver').DataTable({     
            "processing": true,     
            "serverSide": true,     
            "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],      
            "dom": '<"bottom"rtflp>',       
            "searching": false,     
            "pagingType": "full_numbers",       
            "deferRender": true,  
            "scrollX" : "100%",
            "scrollY" : "410px",
            "scrollCollapse" : false,
            "ajax": {       
                "url": "/ecRefundManager/ecRefundOverList.action",      
                "data": function (d) {      
                        d.quickSearch = quickSearch;        
                        d.formJson = JSON.stringify(searchCondition);       
                    }       
                },      
            "tableTools": {     
                "sRowSelect": "bootstrap"       
            },      
            "columns": [        
                 {"data": "ecRefundItemShow"}   
//                ,{"data": "exceptionType"}  
//                ,{"data": "prjName"}    
                ,{"data": "shopName"}   
                ,{"data": "shopType"}
                ,{"data": "buyerNick"}
                ,{"data": "ecTradeCode"}
                ,{"data": "ecRefundCode"}
                ,{"data": "refundStatusNm"}  
                ,{"data": "refundTradeStatus"} 
                ,{"data": "refundCreateTime"}
                ,{"data": "refundTimeout"}
                ,{"data": "refundTime"}
                ],  
            "columnDefs": [{        
                "orderable": false,     
                "targets": [0]      
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [1] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [2] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [3] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [4] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [5] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [6] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [7] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [8] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [9] 
            } ,{
                "className" : "truncate-text tooltip-column-detail",
                "targets": [10] 
            }   
            ],      
            "order": [[9, "asc"]]      
        }).on('draw.dt',  function() {
        	//解决因滚动条导致的列对不齐问题
            $(".dataTables_scrollBody").css("overflow-y","overlay");
        });
}   

/**         
* 等待卖家同意 列表           
* @returns         
*/         
function getSellerAgree(){           
 //如果已经初期化过，不用重新定义，直接重画表格        
 if (tecRefundSellerAgree!=null && tecRefundSellerAgree != undefined && ""!=tecRefundSellerAgree){     
     tecRefundSellerAgree.draw();  
     return ;    
 }       
 tecRefundSellerAgree = $('#tecRefundSellerAgree').DataTable({       
         "processing": true,     
         "serverSide": true,     
         "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],      
         "dom": '<"bottom"rtflp>',       
         "searching": false,     
         "pagingType": "full_numbers",       
         "deferRender": true,    
         "scrollX" : "100%",
         "scrollY" : "410px",
         "scrollCollapse" : false,
         "ajax": {       
             "url": "/ecRefundManager/ecRefundSellerAgreeList.action",     
             "data": function (d) {      
                     d.quickSearch = quickSearch;        
                     d.formJson = JSON.stringify(searchCondition);       
                 }       
             },      
         "tableTools": {     
             "sRowSelect": "bootstrap"       
         },      
         "columns": [        
             {"data": "ecRefundItemShow"}   
             ,{"data": "outTimeshow"}
             ,{"data": "shopName"}   
             ,{"data": "shopType"}
             ,{"data": "buyerNick"}
             ,{"data": "ecTradeCode"}
             ,{"data": "ecRefundCode"}
             ,{"data": "refundStatusNm"}  
             ,{"data": "refundTradeStatus"} 
             ,{"data": "refundCreateTime"}
             ,{"data": "refundTimeout"}
             ,{"data": "refundTime"}
             ,{"data": "closeTime"}
             ],  
         "columnDefs": [{        
             "orderable": false,     
             "targets": [0]      
         },{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [2] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [4] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [5] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [6] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [7] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [8] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [9] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [10] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [11] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [12] 
         } 
         ],      
         "order": [[9, "asc"]]      
     }).on('draw.dt',  function() {
     	//解决因滚动条导致的列对不齐问题
         $(".dataTables_scrollBody").css("overflow-y","overlay");
     });
} 

/**         
* 等待买家退货 列表           
* @returns         
*/         
function getBuyerSend(){           
 //如果已经初期化过，不用重新定义，直接重画表格        
 if (tecRefundBuyerSend!=null && tecRefundBuyerSend != undefined && ""!=tecRefundBuyerSend){     
     tecRefundBuyerSend.draw();  
     return ;    
 }       
 tecRefundBuyerSend = $('#tecRefundBuyerSend').DataTable({       
         "processing": true,     
         "serverSide": true,     
         "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],      
         "dom": '<"bottom"rtflp>',       
         "searching": false,     
         "pagingType": "full_numbers",       
         "deferRender": true,   
         "scrollX" : "100%",
         "scrollY" : "410px",
         "scrollCollapse" : false,
         "ajax": {       
             "url": "/ecRefundManager/ecRefundBuyerSendList.action",     
             "data": function (d) {      
                     d.quickSearch = quickSearch;        
                     d.formJson = JSON.stringify(searchCondition);       
                 }       
             },      
         "tableTools": {     
             "sRowSelect": "bootstrap"       
         },      
         "columns": [        
             {"data": "ecRefundItemShow"}   
             ,{"data": "outTimeshow"}
             ,{"data": "shopName"}   
             ,{"data": "shopType"}
             ,{"data": "buyerNick"}
             ,{"data": "ecTradeCode"}
             ,{"data": "ecRefundCode"}
             ,{"data": "refundStatusNm"}  
             ,{"data": "refundTradeStatus"} 
             ,{"data": "refundCreateTime"}
             ,{"data": "refundTimeout"}
             ,{"data": "refundTime"}
             ,{"data": "closeTime"}
             ],  
         "columnDefs": [{        
             "orderable": false,     
             "targets": [0]      
         },{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [2] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [4] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [5] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [6] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [7] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [8] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [9] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [10] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [11] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [12] 
         }          
         ],      
         "order": [[9, "asc"]]      
     }).on('draw.dt',  function() {
     	//解决因滚动条导致的列对不齐问题
         $(".dataTables_scrollBody").css("overflow-y","overlay");
     });
}

/**         
* 等待卖家确认收货 列表           
* @returns         
*/         
function getSellerRecive(){           
 //如果已经初期化过，不用重新定义，直接重画表格        
 if (tecRefundSellerRecive!=null && tecRefundSellerRecive != undefined && ""!=tecRefundSellerRecive){     
     tecRefundSellerRecive.draw();  
     return ;    
 }       
 tecRefundSellerRecive = $('#tecRefundSellerRecive').DataTable({       
         "processing": true,     
         "serverSide": true,     
         "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],      
         "dom": '<"bottom"rtflp>',       
         "searching": false,     
         "pagingType": "full_numbers",       
         "deferRender": true,   
         "scrollX" : "100%",
         "scrollY" : "410px",
         "scrollCollapse" : false,
         "ajax": {       
             "url": "/ecRefundManager/ecRefundSellerReciveList.action",     
             "data": function (d) {      
                     d.quickSearch = quickSearch;        
                     d.formJson = JSON.stringify(searchCondition);       
                 }       
             },      
         "tableTools": {     
             "sRowSelect": "bootstrap"       
         },      
         "columns": [        
             {"data": "ecRefundItemShow"}   
             ,{"data": "outTimeshow"}
             ,{"data": "shopName"}   
             ,{"data": "shopType"}
             ,{"data": "buyerNick"}
             ,{"data": "ecTradeCode"}
             ,{"data": "ecRefundCode"}
             ,{"data": "refundStatusNm"}  
             ,{"data": "refundTradeStatus"} 
             ,{"data": "refundCreateTime"}
             ,{"data": "refundTimeout"}
             ,{"data": "refundTime"}
             ,{"data": "closeTime"}
             ],  
         "columnDefs": [{        
             "orderable": false,     
             "targets": [0]      
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [2] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [4] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [5] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [6] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [7] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [8] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [9] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [10] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [11] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [12] 
         }   
         ],      
         "order": [[9, "asc"]]      
     }).on('draw.dt',  function() {
     	//解决因滚动条导致的列对不齐问题
         $(".dataTables_scrollBody").css("overflow-y","overlay");
     });
}

/**         
* 卖家拒绝退款 列表           
* @returns         
*/         
function getSellerReject(){           
 //如果已经初期化过，不用重新定义，直接重画表格        
 if (tecRefundSellerReject!=null && tecRefundSellerReject != undefined && ""!=tecRefundSellerReject){     
     tecRefundSellerReject.draw();  
     return ;    
 }       
 tecRefundSellerReject = $('#tecRefundSellerReject').DataTable({       
         "processing": true,     
         "serverSide": true,     
         "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],      
         "dom": '<"bottom"rtflp>',       
         "searching": false,     
         "pagingType": "full_numbers",       
         "deferRender": true,    
         "scrollX" : "100%",
         "scrollY" : "410px",
         "scrollCollapse" : false,
         "ajax": {       
             "url": "/ecRefundManager/ecRefundSellerRejectList.action",     
             "data": function (d) {      
                     d.quickSearch = quickSearch;        
                     d.formJson = JSON.stringify(searchCondition);       
                 }       
             },      
         "tableTools": {     
             "sRowSelect": "bootstrap"       
         },      
         "columns": [        
             {"data": "ecRefundItemShow"}   
             ,{"data": "outTimeshow"}
             ,{"data": "shopName"}   
             ,{"data": "shopType"}
             ,{"data": "buyerNick"}
             ,{"data": "ecTradeCode"}
             ,{"data": "ecRefundCode"}
             ,{"data": "refundStatusNm"}  
             ,{"data": "refundTradeStatus"} 
             ,{"data": "refundCreateTime"}
             ,{"data": "refundTimeout"}
             ,{"data": "refundTime"}
             ,{"data": "closeTime"}
             ],  
         "columnDefs": [{        
             "orderable": false,     
             "targets": [0]      
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [2] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [4] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [5] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [6] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [7] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [8] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [9] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [10] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [11] 
         } ,{
             "className" : "truncate-text tooltip-column-detail",
             "targets": [12] 
         }   
         ],      
         "order": [[9, "asc"]]      
     }).on('draw.dt',  function() {
     	//解决因滚动条导致的列对不齐问题
         $(".dataTables_scrollBody").css("overflow-y","overlay");
     });
}

///**         
// * 待买家 列表           
// * @returns         
// */         
//function getWaitebuyer(){           
//    //如果已经初期化过，不用重新定义，直接重画表格        
//    if (tecRefundwaitbuyer!=null && tecRefundwaitbuyer != undefined && ""!=tecRefundwaitbuyer){     
//        tecRefundwaitbuyer.draw();  
//        return ;    
//    }       
//    tecRefundwaitbuyer = $('#tecRefundwaitbuyer').DataTable({       
//            "processing": true,     
//            "serverSide": true,     
//            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],      
//            "dom": '<"bottom"rtflp>',       
//            "searching": false,     
//            "pagingType": "full_numbers",       
//            "deferRender": true,        
//            "ajax": {       
//                "url": "/ecRefundManager/ecRefundWaitBuyerList.action",     
//                "data": function (d) {      
//                        d.quickSearch = quickSearch;        
//                        d.formJson = JSON.stringify(searchCondition);       
//                    }       
//                },      
//            "tableTools": {     
//                "sRowSelect": "bootstrap"       
//            },      
//            "columns": [        
//                 {"data": "ecRefundItemShow"}   
//                ,{"data": "exceptionType"}  
//                ,{"data": "prjName"}    
//                ,{"data": "shopName"}   
//                ,{"data": "shopType"}
//                ,{"data": "buyerNick"}
//                ,{"data": "ecTradeCode"}
//                ,{"data": "ecRefundCode"}
//                ,{"data": "refundStatusNm"}  
//                ,{"data": "refundTradeStatus"} 
//                ,{"data": "refundCreateTime"}
//                ,{"data": "refundTimeout"}
//                ],  
//            "columnDefs": [{        
//                "orderable": false,     
//                "targets": [0]      
//            }   
//            ],      
//            "order": [[10, "asc"]]      
//        });
//}   
//
///**         
// * 待卖家 列表           
// * @returns         
// */         
//function getWaiteseller(){          
//    //如果已经初期化过，不用重新定义，直接重画表格        
//    if (tecRefundwaiteseller!=null && tecRefundwaiteseller != undefined && ""!=tecRefundwaiteseller){       
//        tecRefundwaiteseller.draw();    
//        return ;    
//    }       
//    tecRefundwaiteseller = $('#tecRefundwaiteseller').DataTable({       
//            "processing": true,     
//            "serverSide": true,     
//            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],      
//            "dom": '<"bottom"rtflp>',       
//            "searching": false,     
//            "pagingType": "full_numbers",       
//            "deferRender": true,        
//            "ajax": {       
//                "url": "/ecRefundManager/ecRefundWaitSellerList.action",        
//                "data": function (d) {
//                        d.quickSearch = quickSearch;        
//                        d.formJson = JSON.stringify(searchCondition);       
//                    }       
//                },      
//            "tableTools": {     
//                "sRowSelect": "bootstrap"       
//            },      
//            "columns": [        
//                 {"data": "ecRefundItemShow"}   
//                ,{"data": "exceptionType"}  
//                ,{"data": "outTimeshow"}
//                ,{"data": "prjName"}    
//                ,{"data": "shopName"}   
//                ,{"data": "shopType"}
//                ,{"data": "buyerNick"}
//                ,{"data": "ecTradeCode"}
//                ,{"data": "ecRefundCode"}
//                ,{"data": "refundStatusNm"}  
//                ,{"data": "refundTradeStatus"} 
//                ,{"data": "refundCreateTime"}
//                ,{"data": "refundTimeout"}
//                ],  
//            "columnDefs": [{        
//                "orderable": false,     
//                "targets": [0]      
//            }       
//            ],      
//            "order": [[11, "asc"]]      
//        });
//}   
//
///**         
// * 待处理 列表           
// * @returns         
// */         
//function getEcRefundnoDeal(){           
//    //如果已经初期化过，不用重新定义，直接重画表格        
//    if (tecRefundnoDeal!=null && tecRefundnoDeal != undefined && ""!=tecRefundnoDeal){      
//        tecRefundnoDeal.draw(); 
//        return ;    
//    }       
//    tecRefundnoDeal = $('#tecRefundnoDeal').DataTable({     
//            "processing": true,     
//            "serverSide": true,     
//            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],      
//            "dom": '<"bottom"rtflp>',       
//            "searching": false,     
//            "pagingType": "full_numbers",       
//            "deferRender": true,        
//            "ajax": {       
//                "url": "/ecRefundManager/ecRefundNoDealList.action",        
//                "data": function (d) {      
//                        d.quickSearch = quickSearch;        
//                        d.formJson = JSON.stringify(searchCondition);       
//                    }       
//                },      
//            "tableTools": {     
//                "sRowSelect": "bootstrap"       
//            },      
//            "columns": [        
//                 {"data": "ecRefundItemShow"}   
//                ,{"data": "exceptionType"}  
//                ,{"data": "outTimeshow"}
//                ,{"data": "prjName"}    
//                ,{"data": "shopName"}   
//                ,{"data": "shopType"}
//                ,{"data": "buyerNick"}
//                ,{"data": "ecTradeCode"}
//                ,{"data": "ecRefundCode"}
//                ,{"data": "refundStatusNm"}  
//                ,{"data": "refundTradeStatus"} 
//                ,{"data": "refundCreateTime"}
//                ,{"data": "refundTimeout"}
//                ,{"data": "refundTime"}
//                ,{"data": "closeTime"}
//                ],  
//            "columnDefs": [{        
//                "orderable": false,     
//                "targets": [0]      
//            }
//            ],      
//            "order": [[11, "asc"]]      
//        });
//}   

/**         
 * 取得tab上面的数字           
 * @returns         
 */         
function getCounts(){           
    //待处理数字,待卖家操作,待买家操作,已完成数字,已废弃数字     
    $.ajax({        
        type:"POST",            
        url:"/ecRefundManager/getTabCounts.action?quickSearch=" + encodeURI(encodeURI(quickSearch)) ,//+ "&formJson=" + JSON.stringify(searchCondition) ,
        data:JSON.stringify(searchCondition),
        contentType: "application/json;charset=utf-8",          
        dataType: "json",           
        async: true,//同步            
        success:function(data) {            
            if (data.result == "success") {         
                $("#portlettabcanceledid").html("已废弃(" + data.countCancel +")");        
                $("#portlettaboverid").html("退款完成(" + data.countOver +")");     
//                $("#portlettabwaitebuyerid").html("待买家操作(" + data.countWaitForBuyer +")");      
//                $("#portlettabwaitesellerid").html("待卖家操作(" + data.countWaitForSeller +")");        
//                $("#portlettabnoDealid").html("待处理(" + data.countWait +")");    
                $("#portlettabselleragreeid").html("等待卖家同意(" + data.countAgree +")");
                $("#portlettabbuyersendid").html("等待买家退货(" + data.countSend +")");
                $("#portlettabsellerreciveid").html("等待卖家确认收货(" + data.countRecive +")");
                $("#portlettabsellerrejectid").html("卖家拒绝退款(" + data.countReject +")");
            } else {            
                window.top.window.showModalAlert(data.msg);     
            }           
        },          
        error:function(XMLHttpRequest, textStatus) {            
            if (XMLHttpRequest.status == 500) {         
                var result = eval("(" + XMLHttpRequest.responseText + ")");         
                alert(result.errorObject.errorText);            
            }           
        }           
    });
}

function refresh(){ 
    
    
    $('#quickSearch').val("");
    quickSearch = "";
    $("#advSearchReset").click();
    searchCondition = {};
    if (!$("#advSearchPanel").is(":hidden")){
        $("#btnAdvSearch").click();   
    }  
    $("div .active").each(function(){       
        switch ($(this).attr("id")) {   
        case "portlettabcanceled":  //已废弃
            tecRefundcanceled.draw();
            break;
        case "portlettabover":      //已完成
            tecRefundOver.draw();   
            break;      
//        case "portlettabwaitebuyer":        //待买家
//            tecRefundwaitbuyer.draw();  
//            break;      
//        case "portlettabwaiteseller":       //待卖家
//            tecRefundwaiteseller.draw();    
//            break;      
//        case "portlettabnoDeal":        //待处理
//            tecRefundnoDeal.draw(); 
//            break;
        case "portlettabselleragree":           //等待卖家同意
            tecRefundSellerAgree.draw();
            break;
        case "portlettabbuyersend":             //等待买家退货
            tecRefundBuyerSend.draw();
            break;
        case "portlettabsellerrecive":          //等待卖家确认收货
            tecRefundSellerRecive.draw();
            break;
        case "portlettabsellerreject":          //卖家拒绝退款
            tecRefundSellerReject.draw();
            break;            
        default:    
            break;  
        }   
    });     
    getCounts();        
}           

/**         
 *          
 * @returns         
 */         
function exportEcRefund(){          
    var fileName = "";      
    var sql = "";       
    $("div .active").each(function(){       
        switch ($(this).attr("id")) {   
        case "portlettabcanceled":  //已废弃
            fileName = "已废弃";
            sql = 'exportSelectRefundCanceled';
            break;
        case "portlettabover":      //已完成
            fileName = "退款完成";   
            sql = 'exportSelectRefundOver'; 
            break;    
        case "portlettabsellerreject":          //卖家拒绝退款
            fileName = "卖家拒绝退款";   
            sql = 'exportSelectSellerReject'; 
            break;
        case "portlettabsellerrecive":          //等待卖家确认收货
            fileName = "等待卖家确认收货";   
            sql = 'exportSelectSellerRecive'; 
            break;
        case "portlettabbuyersend":             //等待买家退货
            fileName = "等待买家退货";   
            sql = 'exportSelectBuyerSend'; 
            break;
        case "portlettabselleragree":             //等待卖家同意
            fileName = "等待卖家同意";   
            sql = 'exportSelectSellerAgree'; 
            break;
//        case "portlettabwaitebuyer":        //待买家
//            fileName = "待买家操作";   
//            sql = 'exportSelectWaitebuyer'; 
//            break;      
//        case "portlettabwaiteseller":       //待卖家
//            fileName = "待卖家操作";   
//            sql = 'exportSelectWaiteseller';    
//            break;      
//        case "portlettabnoDeal":        //待处理
//            fileName = "待处理";   
//            sql = 'exportSelectRefundNoDeal';   
//            break;      
        default:    
            break;  
        }   
    });     
            
    //特殊情况（附加导出字段）      
    var obj = new Object();     
    obj.name = "项目名称";      
    obj.value = "prjName";  
    
    var obj1 = new Object();        
    obj1.name = "店铺名称";     
    obj1.value = "shopName";
    
    var obj2 = new Object();        
    obj2.name = "来源";       
    obj2.value = "shopType";
    
    var obj3 = new Object();        
    obj3.name = "客户ID";     
    obj3.value = "buyerNick";
    
    var obj4 = new Object();        
    obj4.name = "平台交易号";        
    obj4.value = "ecTradeCode";
    
    var obj5 = new Object();        
    obj5.name = "平台退款单号";       
    obj5.value = "ecRefundCode";
    
    var obj6 = new Object();        
    obj6.name = "退款状态";     
    obj6.value = "refundStatus";    
    
    var obj7 = new Object();        
    obj7.name = "交易状态";     
    obj7.value = "ecTradeStus"; 
    
    var obj8 = new Object();        
    obj8.name = "制单时间";     
    obj8.value = "refundCreateTime";    
    
    var obj9 = new Object();        
    obj9.name = "超时时间";     
    obj9.value = "refundTimeout";
    
    var obj10 = new Object();       
    obj10.name = "退款时间";        
    obj10.value = "refundTime";
    
    var obj11 = new Object();       
    obj11.name = "取消时间";        
    obj11.value = "closeTime";
    
//    var obj12 = new Object();       
//    obj12.name = "异常描述";        
//    obj12.value = "errDesc";
    
    var obj13 = new Object();       
    obj13.name = "平台商品编码";      
    obj13.value = "ecItemCode";     
    
    var obj14 = new Object();       
    obj14.name = "平台商品名称";      
    obj14.value = "ecItemName";     
    
    var obj15 = new Object();       
    obj15.name = "平台规格编码";      
    obj15.value = "ecSkuCode";      
    
    var obj16 = new Object();       
    obj16.name = "平台规格名称";      
    obj16.value = "ecSkuName";
    
    var obj17 = new Object();       
    obj17.name = "平台状态";        
    obj17.value = "refundStatus";
    
//    var obj18 = new Object();       
//    obj18.name = "分单店铺";        
//    obj18.value = "splitShopName";
    
    var obj19 = new Object();       
    obj19.name = "系统状态";        
    obj19.value = "erpStatus";
    
    var obj20 = new Object();       
    obj20.name = "买家是否退货";      
    obj20.value = "hasGoodReturn";
    
    var obj21 = new Object();       
    obj21.name = "退款金额";        
    obj21.value = "refundFee";
    
    var obj22 = new Object();       
    obj22.name = "退款原因";        
    obj22.value = "refundReason";
    
    var obj23 = new Object();       
    obj23.name = "退款阶段";        
    obj23.value = "refundPhase";
    
    var obj24 = new Object();       
    obj24.name = "退回物流单号";      
    obj24.value = "lgstNo";
    
    var ob = [obj,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj8,obj9,obj10,obj11,obj13,obj14,obj15,obj16,obj17,obj19,obj20,obj21,obj22,obj23,obj24];      
    extraFieldJson = JSON.stringify(ob);        
            
    exportList('','/ecRefundManager/exportCheck.action','/ecRefundManager/export.action',sql,fileName,'frmAdvSearch',extraFieldJson)        
}           
